package botcraft.server;

import java.util.concurrent.BlockingQueue;
import botcraft.game.Game;

public class Dispatcher implements Runnable {
	private final BlockingQueue<String> inputQueue;
	private final BlockingQueue<String>[] outputQueues;

	public Dispatcher(final BlockingQueue<String> inputQueue, final BlockingQueue<String>[] outputQueues, final Game game) {
		this.inputQueue = inputQueue;
		this.outputQueues = outputQueues;
	}

	@Override
	public void run() {
		while (!Thread.interrupted()) {
			try {
				final String command = inputQueue.take();
				for (BlockingQueue<String> outputQueue : outputQueues)
					outputQueue.put(command);
			} catch (InterruptedException e) {
				return;
			}
		}
	}
}
